﻿using Infragistics.Controls.Schedules;
using Infragistics.Windows.DockManager.Events;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Input;
using VNet.VisiSuite.Controls;
using VNet.VisiSuite.VisiAdmin.Controls;
using VNet.VisiSuite.VisiAdmin.Models;
using VNet.VisiSuite.VisiAdmin.ViewModels;

namespace VNet.VisiSuite.VisiAdmin.Views
{
    public partial class AreaDetailsView : VisiPage
    {

        public AreaDetailsView()
        {
            InitializeComponent();
            
        }

        private void PaneDragStarting(object sender, PaneDragStartingEventArgs e)
        {
            e.Cancel = true;
        }

        private void rcDataGrid_InitializeRecord(object sender, Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs e)
        {
            if (!e.ReInitialize)
                e.Record.IsExpanded = true;
        }

        private void srcDataGrid_InitializeRecord(object sender, Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs e)
        {
            if (!e.ReInitialize)
                e.Record.IsExpanded = true;
        }
        private void xtg_InitializeRecord(object sender, Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs e)
        {
            if (!e.ReInitialize)
                e.Record.IsExpanded = true;
        }

        public override IList<VNetMenuItem> BottomMenuItems()
        {
            var viewModel = DataContext as AreaDetailsViewModel;
            if (viewModel == null) return null;

            return viewModel.BottomMenuItems;
        }

        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {

        }

        //void XamScheduleDataManager_ActivityRemoving(object sender, ActivityRemovingEventArgs e)
        //{
        //   // AddToLog("XamScheduleDataManager_ActivityRemoving");
        //}

        //void XamScheduleDataManager_ActivityRemoved(object sender, ActivityRemovedEventArgs e)
        //{
        //  //  AddToLog("XamScheduleDataManager_ActivityRemoved");
        //}

        //void XamScheduleDataManager_ActivityChanging(object sender, ActivityChangingEventArgs e)
        //{
        //  //  AddToLog("XamScheduleDataManager_ActivityChanging");
        //}

        //void XamScheduleDataManager_ActivityChanged(object sender, ActivityChangedEventArgs e)
        //{
        //  //  AddToLog("XamScheduleDataManager_ActivityChanged");
        //}

        //void XamScheduleDataManager_ActivityAdding(object sender, ActivityAddingEventArgs e)
        //{
        //  //  AddToLog("XamScheduleDataManager_ActivityAdding");
        //}

        //void XamScheduleDataManager_ActivityAdded(object sender, ActivityAddedEventArgs e)
        //{
        //   // AddToLog("XamScheduleDataManager_ActivityAdded");
        //}

        //private void monthView_SelectedTimeRangeChanged(object sender, RoutedPropertyChangedEventArgs<DateRange?> e)
        //{
        //    var viewModel = DataContext as AreaDetailsViewModel;
        //    if (viewModel == null) return;

        //   viewModel.CloneAndBindingSchedule((ScheduleModel)_selectedObject);
        //}

        //void monthView_ActiveCalendarChanged(object sender, RoutedPropertyChangedEventArgs<ResourceCalendar> e)
        //{
        //   // AddToLog("XamMonthView_ActiveCalendarChanged");
        //}

        //void monthView_SelectedActivitiesChanged(object sender, SelectedActivitiesChangedEventArgs e)
        //{
        //  //  AddToLog("XamMonthView_SelectedActivitiesChanged");
        //}



        private void XamScheduleDataManager1ActivityAdded(object sender, ActivityAddedEventArgs e)
        {

            var viewModel = DataContext as AreaDetailsViewModel;


            if (viewModel == null) return;

            foreach (object x in listScheduleDataConnector1.AppointmentItemsSource)
            {

                var app = new ScheduleModel();

            }

            //    viewModel.SubmitChanges();
        }

        private void XamScheduleDataManager1ActivityChanged(object sender, ActivityChangedEventArgs e)
        {
            MessageBox.Show("Changed");
        }


        private void XamScheduleDataManager1ActivityRemoved(object sender, ActivityRemovedEventArgs e)
        {
            //  this.resourceDomainDataSource.DomainContext.SubmitChanges();
        }


        private void XamScheduleDataManager_OnActivityChanging(object sender, ActivityChangingEventArgs e)
        {
            //MessageBox.Show("Changing");
        }

        private void XamScheduleDataManager_OnActivityDialogDisplaying(object sender, ActivityDialogDisplayingEventArgs e)
        {
            //MessageBox.Show("DialogDisplaying");
            //e.Cancel = true;
        }

        private void MonthViewScheduledDowntime_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (MonthViewScheduledDowntime.SelectedActivities.Count <= 0)
                return;

            var vm = this.TryFindResource("AreaDetailsViewModel") as AreaDetailsViewModel;
            var monthView = sender as XamMonthView;
            ScheduleModel activity = new ScheduleModel();
            if (vm != null && monthView != null)
            {
                activity.ScheduleId = int.Parse(monthView.SelectedActivities[0].Id);
                activity.AreaId = int.Parse(monthView.SelectedActivities[0].Categories);
                activity.Subject = monthView.SelectedActivities[0].Subject;  
                activity.StartTime = monthView.SelectedActivities[0].Start;
                activity.EndTime = monthView.SelectedActivities[0].End;
                activity.ReasonCodeId = int.Parse(monthView.SelectedActivities[0].Description);
                activity.ScheduleRepeatId = monthView.SelectedActivities[0].RecurrenceVersion;
                activity.CreatedBy = monthView.SelectedActivities[0].StartTimeZoneId;
                activity.CreatedDate = monthView.SelectedActivities[0].OriginalOccurrenceStart.ToShortDateString();
                activity.LastUpdatedBy = monthView.SelectedActivities[0].EndTimeZoneId;
                activity.LastUpdatedDate = monthView.SelectedActivities[0].OriginalOccurrenceEnd.ToShortDateString();
                vm.SelectedObject = activity;
            }
            
        }
    }
}
